package com.lvchanglong

import org.apache.ibatis.io.Resources
import org.apache.ibatis.session.SqlSessionFactory
import org.apache.ibatis.session.SqlSessionFactoryBuilder

/**
 * Example Groovy class.
 */
class Example {

    static SqlSessionFactory sessionFactory = null

    static {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml"); //得到配置文件的输入流mybatis-config.xml
        sessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //创建SessionFactory
    }

    /**
     * 读
     */
    static def show() {
        def session = sessionFactory.openSession()
        try {
            def mapper = session.getMapper(RobotMapper)
            def robot = mapper.get(2)
            println robot
            println robot.mouths
            session.commit()
        } finally {
            session.close();
        }
    }

    static main(args) {
        try {
            this.show()
        } catch (Exception e) {
            e.printStackTrace()
        } finally {

        }
    }

}
